<template>
  <div class="mainsu">
    <div class="main_spac1">
      <div class="main_white padding10 paddingBottom20">
        <div class="mainor_form">
          <div class="mainor_te">
            <router-link to="/order/return/add" class="mainor_tea"
              >创建退货单</router-link
            >
          </div>
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="70px"
          >
            <el-form-item label="状态" prop="status">
              <el-select
                v-model.trim="form.status"
                placeholder="状 态"
                class="wid220"
              >
                <el-option label="所有" :value="parseInt(0)"></el-option>
                <el-option
                  v-for="(statusList, index) in statusList"
                  :key="index"
                  :label="statusList"
                  :value="parseInt(index + 1)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="申请日期" prop="createTime">
              <el-date-picker
                v-model="createTime"
                type="daterange"
                class="time220"
                :editable="false"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                :clearable="false"
                :picker-options="dateOption"
              />
            </el-form-item>
            <el-form-item label="用户" prop="uid">
              <change-user-input
                ref="changeUserInput"
                @sendValue="getUser"
                @clear="clearUid"
              ></change-user-input>
            </el-form-item>

            <div class="more el-form-item" @click="more">
              <span>更多</span>
              <i :class="[{ on: moredata }, ' el-icon-arrow-down']"></i>
            </div>
            <div class="clearfix"></div>
            <el-collapse-transition>
              <div v-if="moredata">
                <div>
                  <el-form-item label="退货单号" prop="order_sn">
                    <el-input
                      v-model.trim="form.order_sn"
                      placeholder="退货单号"
                      clearable
                      class="wid220"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="订单号" prop="related_order_sn">
                    <el-input
                      v-model.trim="form.related_order_sn"
                      placeholder="关联订单号"
                      clearable
                      class="wid220"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label="入库单号" prop="storage_order_sn">
                    <el-input
                      v-model.trim="form.storage_order_sn"
                      placeholder="关联入库单号"
                      clearable
                      class="wid220"
                    ></el-input>
                  </el-form-item>

                  <el-form-item label="审核日期" prop="check_createTime">
                    <el-date-picker
                      v-model="check_createTime"
                      type="daterange"
                      class="time220"
                      :editable="false"
                      unlink-panels
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      value-format="yyyy-MM-dd"
                      :clearable="false"
                      :picker-options="dateOption"
                    />
                  </el-form-item>
                </div>
              </div>
            </el-collapse-transition>
            <el-form-item class="btn_box" label="">
              <el-button class="reset" type="primary" @click="reset"
                >重置</el-button
              >
              <el-button
                type="primary"
                @click="getArticleList"
                :loading="listLoading"
                >搜索</el-button
              >
            </el-form-item>
          </el-form>
        </div>

        <div class="main_table marginTop10" style="min-height: 550px">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list.data"
            element-loading-text="加载中"
            fit
            border
            highlight-current-row
            @selection-change="handleSelectionChange"
            :header-cell-class-name="this.$verticaline"
          >
            <el-table-column type="selection" :selectable="selectInit" />
            <el-table-column
              label="用户名称"
              :show-overflow-tooltip="true"
              width="100"
              prop="nickname"
            />
            <el-table-column
              label="退货单号"
              :show-overflow-tooltip="true"
              width="220"
              prop="order_sn"
            />

            <el-table-column
              label="退货金额"
              :show-overflow-tooltip="true"
              width="120"
              prop="apply_money"
            >
            </el-table-column>
            <el-table-column
              label="关联订单"
              width="180"
              :show-overflow-tooltip="true"
              prop="related_order_sn"
            />

            <el-table-column
              label="支付方式"
              :show-overflow-tooltip="true"
              width="120"
              prop="status"
            >
              <template slot-scope="scope"
                ><span :class="'pay_type' + scope.row.is_prior_payment">
                  {{
                    scope.row.is_prior_payment == 0 ? "货到付款" : "在线支付"
                  }}
                </span></template
              >
            </el-table-column>
            <el-table-column
              label="关联入库单"
              width="220"
              prop="storage_order_sn"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="退货原因"
              width="180"
              prop="return_remark"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              label="申请时间"
              :show-overflow-tooltip="true"
              prop="order_sn"
            >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at, "{y}-{m}-{d}")
              }}</template>
            </el-table-column>
            <el-table-column
              label="审核日期"
              :show-overflow-tooltip="true"
              prop="order_sn"
            >
              <template slot-scope="scope" v-if="scope.row.status != 0">{{
                scope.row.check_time != 0
                  ? parseTime(scope.row.check_time, "{y}-{m}-{d}")
                  : ""
              }}</template>
            </el-table-column>
            <el-table-column
              label="状态"
              :show-overflow-tooltip="true"
              prop="order_pay_status"
            >
              <template slot-scope="scope"
                ><span :class="'order' + scope.row.status">
                  {{ statusList[scope.row.status] }}</span
                ></template
              >
            </el-table-column>
            <el-table-column
              label="管理操作"
              align="left"
              fixed="right"
              width="200"
              class-name="main_hei"
            >
              <template slot-scope="scope">
                <router-link :to="'/order/return/see/' + scope.row.id">
                  <el-link type="success">查看</el-link>
                </router-link>

                <router-link
                  v-if="scope.row.status == 0"
                  :to="'/order/return/check/' + scope.row.id"
                >
                  <el-link type="warning"><span>审核</span></el-link>
                </router-link>

                <el-link @click="print(scope.row.id)">打印</el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <el-pagination
              :current-page="current.page"
              :page-sizes="[20, 50, 100, 200]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>
      </div>
    </div>
    <!-- 打印子组件 -->
    <order-print
      ref="printTemplate"
      v-show="false"
      id="printname"
    ></order-print>
  </div>
</template>

<script>
import dateOption from "@/options/dateOption";
import { mapGetters } from "vuex";
import { order_return_index } from "@/api/order/orderReturn";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";
import OrderPrint from "@/views/order/orderPrint.vue";
export default {
  components: {
    OrderPrint,
  },
  computed: {
    ...mapGetters(["avatar"]),
    reverseSum() {
      return this.percent_list.reverse();
    },
  },
  data() {
    return {
      dateOption,
      isloading: true,
      // 时间
      parseTime,
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 更多
      moredata: false,
      // 列表数据
      list: {
        data: [],
        total: "",
      },
      statusList: [],
      order_status: [],
      id: "",
      seeFormVisible: false,
      listLoading: false,
      // 搜索
      form: {
        status: null, //状态
        start_time: "", //申请开始时间
        uid: "",
        end_time: "",
        order_sn: "",
        related_order_sn: "",
        storage_order_sn: "",
        check_start_time: "", //审核开始时间
        check_end_time: "",
      },
      createTime: [],
      check_createTime: [],
      // 全选
      selectArr: [],
    };
  },
  mounted() {},
  created() {
    // 列表
    this.order_return_index();
  },
  methods: {
    //获取用户信息
    getUser(data) {
      let uid = data.info.user_id;
      this.form.uid = uid;
      this.order_return_index();
    },
    // 清除用户的uid
    clearUid() {
      this.form.uid = "";
    },
    // 监听全选
    handleSelectionChange(val) {
      this.selectArr = [];
      val.map((item) => {
        this.selectArr.push({ id: item.id });
      });
    },
    // 监听绑定全选不可勾选
    selectInit(row, index) {
      if (row.order_status == 1 && row.order_list_status == 2) {
        return true;
      } else {
        return false;
      }
    },
    // 打印
    print(id) {
      this.printid = id;
      this.$refs.printTemplate.$emit("demo", { id: id, type: "order_return" });
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.order_return_index();
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.form.uid = "";
      this.$refs["changeUserInput"].name = "";
      this.createTime = [];
      this.check_createTime = [];
      this.order_return_index();
    },
    // 更多
    more() {
      this.moredata = !this.moredata;
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.order_return_index();
    },
    changePage(page) {
      this.current.page = page;
      this.order_return_index();
    },
    // 列表

    order_return_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, this.current)) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      order_return_index(data).then((res) => {
        if (res.errcode == 0) {
          this.list = res.data.list;
          this.statusList = res.data.statusList;
          this.order_status = res.data.order_status;
          this.totalCount = res.data.list.total;
          this.listLoading = false;
        } else {
          this.$message.errcode(res.msg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      if (this.createTime.length > 0) {
        form.start_time = this.createTime[0];
        form.end_time = this.createTime[1];
      }
      if (this.check_createTime.length > 0) {
        form.check_start_time = this.check_createTime[0];
        form.check_end_time = this.check_createTime[1];
      }
      return form;
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: calc(100% - 120px);
  }
  .main_num {
    .mainsu_te {
      position: relative;
      top: -1px;
    }
  }
}

.main_dialog {
  .main_table {
    /deep/.el-table__body-wrapper {
      overflow-y: auto;
      height: 400px;
    }
  }
  .main_xq ul li {
    width: 33.33%;
    margin-top: 5px;
    margin-bottom: 5px;
  }
  .progress_list {
    margin-top: 10px;
    p {
      height: 24px;
      line-height: 24px;
    }
    .progress_list_red {
      color: red;
    }
    .progress_list_su {
      color: #03a98e;
    }
  }
}

// 订单状态
.order0 {
  color: #f56c6c;
}
.order1 {
  color: #118ab2;
}
.order2 {
  color: #aacd6e;
}
.order3 {
  color: #073b4c;
}
.order4 {
  color: #cccccc;
}
// 支付状态
.pay_type0 {
  color: #f56c6c;
}
.pay_type1 {
  color: #03a98e;
}
.btn_box {
  padding-left: 35px;
}
</style>
